package com.xianniu.ltc.controller;

import cn.devezhao.commons.web.ServletUtils;
import cn.devezhao.commons.web.WebUtils;
import cn.devezhao.persist4j.engine.ID;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONAware;
import com.alibaba.fastjson.JSONObject;
import com.rebuild.api.Controller;
import com.rebuild.api.RespBody;
import com.rebuild.core.Application;
import com.rebuild.core.UserContextHolder;
import com.rebuild.core.configuration.general.DataListManager;
import com.rebuild.core.privileges.bizz.ZeroEntry;
import com.rebuild.core.support.general.BatchOperatorQuery;
import com.rebuild.utils.ExcelUtils;
import com.rebuild.utils.JSONUtils;
import com.rebuild.web.BaseController;
import com.rebuild.web.user.signup.LoginController;
import com.xianniu.ltc.enums.*;
import com.xianniu.ltc.model.po.*;
import com.xianniu.ltc.model.po.imports.*;
import com.xianniu.ltc.model.po.imports.ImportAccountCountPO;
import com.xianniu.ltc.model.po.imports.ImportAccountPO;
import com.xianniu.ltc.model.vo.XnAccountVO;
import com.xianniu.ltc.model.vo.XnAccountVO;
import com.xianniu.ltc.service.XnAccountService;
import com.xxl.sso.core.entity.ReturnT;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author WangRuiJie
 * @Title: XnAccountController
 * @Package com.xianniu.ltc.controller
 * @Description: 客户管理
 * @date 2021/6/172:55 下午
 */
@RestController
@Slf4j
@RequestMapping(value = "/account")
public class XnAccountController extends BaseController {

    // 限制导入最长行数
    private final Integer MAX_USER_IMPORT = 20000;
    
    @Autowired
    private XnAccountService xnAccountService;

    /*************************************************************** 后台开始 ***************************************************************/
    /**
     * 后台查询客户列表
     * @return
     */
    @GetMapping("/selectAccountForAdmin")
    public ModelAndView selectAccountForAdmin(HttpServletRequest request) {
        final ID user = getRequestUser(request);
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        ModelAndView mv = createModelAndView("/xianniu/admin/account/account-list");
        mv.getModel().put("entityName", "xnaccount");
        mv.getModel().put("entityLabel", "客户管理");
        mv.getModel().put("entityIcon", "entityIcon");
        JSON config = buildAccountAdminDataListConfig();
        mv.getModel().put("DataListConfig", JSON.toJSONString(config));
        return mv;
    }

    /**
     * 新前端调用返回JSON：后台查询客户列表
     * @return
     */
    @GetMapping("/selectAccountForAdmin-new")
    public JSONAware selectAccountForAdminNew(HttpServletRequest request) {
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("entityName", "xnaccount");
        jsonObject.put("entityLabel", "客户管理");
        jsonObject.put("entityIcon", "entityIcon");
        JSON config = buildAccountAdminDataListConfig();
        jsonObject.put("DataListConfig", JSON.toJSONString(config));
        return jsonObject;
    }

    /**
     * 根据ID查询客户详情
     * @param id
     * @return
     */
    @GetMapping("/detailAccount")
    public ModelAndView detailAccount(String id, HttpServletRequest request) {
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        // TODO 未确定前端HTML
        ModelAndView mv = createModelAndView("/xianniu/admin/account/account-view");
        log.info("后台-根据ID查询客户详情:{}", JSON.toJSON(id));
        XnAccountVO vo = xnAccountService.detailAccount(id);
        mv.getModel().put("accountVo", vo);
        return mv;
    }

    /**
     * 新前端调用返回JSON：客户详情
     * @return
     */
    @GetMapping("/detailAccount-new")
    public JSONAware detailAccountNew(String id, HttpServletRequest request) {
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        JSONObject jsonObject = new JSONObject();
        log.info("后台-根据ID查询客户详情:{}", JSON.toJSON(id));
        XnAccountVO vo = xnAccountService.detailAccount(id);
        jsonObject.put("accountVo", vo);
        return jsonObject;
    }


    /**
     * 后台-单个/批量转移分组
     * @param po
     * @return
     */
    @PostMapping("/transferAccountForAdmin")
    public JSONAware transferAccountForAdmin(@RequestBody TransferAccountPO po, HttpServletRequest request) {
        if (po.getAccountIdList().isEmpty()){
            return RespBody.errorl("PlsSet1FieldShowLeast");
        }
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        log.info("后台-单个/批量转移分组:{}", JSON.toJSON(po));
        ReturnT returnT = xnAccountService.transferAccountForAdmin(po);
        if (returnT.getCode() != 200){
            return RespBody.errorl(returnT.getMsg());
        }
        return RespBody.ok();
    }


    /**
     * 后台-单个/删除客户
     * @param idList
     * @return
     */
    @PostMapping("/deleteAccountForAdmin")
    public JSONAware deleteAccountForAdmin(@RequestParam List<String> idList, HttpServletRequest request) {
        if (idList.isEmpty()){
            return RespBody.errorl("PlsSet1FieldShowLeast");
        }
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        log.info("后台-单个/删除客户:{}", JSON.toJSON(idList));
        ReturnT returnT = xnAccountService.deleteAccountForAdmin(idList);
        if (returnT.getCode() != 200){
            return RespBody.errorl(returnT.getMsg());
        }
        return RespBody.ok();
    }

    /**
     * 后台：回收站查询客户列表
     * @return
     */
    @GetMapping("/selectAccountFallbackForAdmin")
    public ModelAndView selectAccountFallbackForAdmin(HttpServletRequest request) {
        final ID user = getRequestUser(request);
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        ModelAndView mv = createModelAndView("/xianniu/admin/account/account-fallback");
        mv.getModel().put("entityName", "xnaccount");
        mv.getModel().put("entityLabel", "客户回收站");
        mv.getModel().put("entityIcon", "entityIcon");
        JSON config = DataListManager.instance.getFieldsLayout("xnaccount", user, tenantCode);
        mv.getModel().put("DataListConfig", JSON.toJSONString(config));
        return mv;
    }

    /**
     * 新前端调用返回JSON：回收站查询客户列表
     * @return
     */
    @GetMapping("/selectAccountFallbackForAdmin-new")
    public JSONAware selectAccountFallbackForAdminNew(HttpServletRequest request) {
        final ID user = getRequestUser(request);
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("entityName", "xnaccount");
        jsonObject.put("entityLabel", "客户回收站");
        jsonObject.put("entityIcon", "entityIcon");
        JSON config = DataListManager.instance.getFieldsLayout("xnaccount", user, tenantCode);
        jsonObject.put("DataListConfig", JSON.toJSONString(config));
        return jsonObject;
    }

    /**
     * 后台-单个/批量还原
     * @param idList
     * @return
     */
    @PostMapping("/resetAccountForAdmin")
    public JSONAware resetAccountForAdmin(@RequestParam List<String> idList, HttpServletRequest request) {
        if (idList.isEmpty()){
            return RespBody.errorl("PlsSet1FieldShowLeast");
        }
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        log.info("后台-单个/批量还原:{}", JSON.toJSON(idList));
        ReturnT returnT = xnAccountService.resetAccountForAdmin(idList);
        if (returnT.getCode() != 200){
            return RespBody.errorl(returnT.getMsg());
        }
        return RespBody.ok();
    }

    /**
     * 功能描述: 下载客户导入模板
     *
     * @Param: [response, request]
     * @Return: void
     * @Author: wrj
     * @Date: 2022/1/21 5:35 下午
     */
    @RequestMapping(value = "/downloadTemplate")
    @ResponseBody
    public void downloadSortImport(HttpServletResponse response){
        String fileName = "导入客户管理模板";
        String sheetName = "导入客户管理模板";
        List<ImportAccountPO> userList = new ArrayList<>();
        ImportAccountPO po = new ImportAccountPO();
        po.setKehumingcheng("客户名称必填");
        po.setKehuzhuangtai("潜在客户/初步接触/持续跟进/成交客户/无效客户");
        po.setRbjibie4("大型客户/中型客户/小型客户");
        po.setArea("朝阳区");
        po.setIndustry("其他/制造业/咨询/娱乐/媒体/政府/教育/服务/电信/能源/金融/零售/非盈利事业/高科技");
        userList.add(po);
        try {
            ExcelUtils.writeExcelTemplate(response, userList, fileName, sheetName, ImportAccountPO.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 导入：同步读，单sheet
     * 注意：这里为了介绍 excel导入导出，代码都写在 controller，实际项目开发中，校验和处理代码建议放到 service
     */
    @PostMapping("/excel/import")
    public ReturnT importData(HttpServletRequest request) {
        CommonsMultipartResolver resolver = new CommonsMultipartResolver(request.getServletContext());
        MultipartFile fileA = null;
        MultipartHttpServletRequest mp = resolver.resolveMultipart(request);
        for (MultipartFile t : mp.getFileMap().values()) {
            // 只允许一个
            fileA = t;
            break;
        }
        if (fileA == null || fileA.isEmpty()) {
            return new ReturnT(400, "文件不存在");
        }
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        Integer successCount=0;
        ImportAccountCountPO countPO = new ImportAccountCountPO();
        // 1.excel同步读取数据
        try {
            List<ImportAccountPO> excelList = EasyExcel.read(new BufferedInputStream(fileA.getInputStream())).head(ImportAccountPO.class).sheet().doReadSync();
            // 2.检查是否大于20000条
            if (excelList.size() > MAX_USER_IMPORT) {
                return new ReturnT(400, "数据不能超过20000行");
            }
            // 3.导入校验所有行列格式
            countPO = checkImportData(excelList);
            // 4.将 userExcelList 转成 userList
            successCount = xnAccountService.saveImportAccount(countPO.getNewList(), tenantCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new ReturnT(200, "导入成功"+successCount+"条,导入失败"+countPO.getErrorCount()+"条");
    }

    /**
     * 校验必填数据信息
     * @param excelList
     * @throws Exception
     */
    private ImportAccountCountPO checkImportData(List<ImportAccountPO> excelList){
        Integer errorCount= 0;
        ImportAccountCountPO po = new ImportAccountCountPO();
        List<ImportAccountPO> newList = new ArrayList<>();
        // 行号从第2行开始
        int rowNo = 2;
        // 遍历校验所有行和列
        for (ImportAccountPO accountPo : excelList) {
            String username = accountPo.getKehumingcheng();
            if (StringUtils.isEmpty(username)) {
                log.info("第{}行客户名称不能为空", rowNo);
                errorCount++;
                continue;
            }
            // 客户级别
            AccountLevelEnum l = AccountLevelEnum.getByValue(accountPo.getRbjibie4());
            if (l != null){
                accountPo.setRbjibie4(l.getKey());
            }else {
                errorCount++;
                continue;
            }
            // 客户状态
            AccountTypeEnum ls =  AccountTypeEnum.getByValue(accountPo.getKehuzhuangtai());
            if (ls != null){
                accountPo.setKehuzhuangtai(ls.getKey());
            }else {
                errorCount++;
                continue;
            }
            // 行业
            IndustryEnum in = IndustryEnum.getValue(accountPo.getIndustry());
            if (in != null){
                accountPo.setIndustry(in.getValue());
            }else {
                errorCount++;
                continue;
            }
            newList.add(accountPo);
        }
        po.setNewList(newList);
        po.setErrorCount(errorCount);
        return po;
    }


    /**
     * 导出客户数据
     */
    @RequestMapping("/excel/export")
    public RespBody exportData(HttpServletRequest request, HttpServletResponse response) {
        final ID user = getRequestUser(request);
        Assert.isTrue(
                Application.getPrivilegesManager().allow(user, ZeroEntry.AllowDataExport),
                getLang(request, "NoOpPrivileges"));
        Integer dataRange = getIntParameter(request, "dr", BatchOperatorQuery.DR_PAGED);
        JSONObject queryData = new JSONObject();
        queryData.put("pageNo", getIntParameter(request, "pageNo"));
        queryData.put("pageSize", getIntParameter(request, "pageSize"));
        queryData.put("param", getParameter(request, "param"));
        queryData.put("_selected", getParameter(request, "_selected"));
        log.info("参数queryData：{}", queryData);
        String fileName = "客户管理"+ DateUtil.now()+".xlsx";
        String sheetName = "客户管理";
        List<XnAccountVO> userList = xnAccountService.selectExportAccountForAdmin(queryData, dataRange);
        List<ImportAccountPO> userExcelList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(userList)){
            for (XnAccountVO vo1 : userList){
                ImportAccountPO AccountPO = new ImportAccountPO();
                BeanUtils.copyProperties(vo1, AccountPO);
                userExcelList.add(AccountPO);
            }
        }
        try {
            ExcelUtils.writeExcel(response, userExcelList, fileName, sheetName, ImportAccountPO.class);
            return RespBody.ok(fileName);
        } catch (Exception e) {
            e.printStackTrace();
            return RespBody.error(e.getLocalizedMessage());
        }
    }

    /*************************************************************** 后台结束 ***************************************************************/
    /*************************************************************** 前台公海开始 ***************************************************************/

    /**
     * 前台-查询公海客户列表
     * @return
     */
    @RequestMapping("/highSea")
    public ModelAndView selectAccountForHighSea(HttpServletRequest request) {
        final ID user = getRequestUser(request);
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        // TODO 未确定前端HTML
        ModelAndView mv = createModelAndView("/xianniu/admin/account/highSea");
        mv.getModel().put("entityName", "xnaccount");
        mv.getModel().put("entityLabel", "公海客户");
        mv.getModel().put("entityIcon", "entityIcon");
        JSON config = DataListManager.instance.getFieldsLayout("xnaccount", user, tenantCode);
        mv.getModel().put("DataListConfig", JSON.toJSONString(config));
        return mv;
    }

    /**
     * 前台-单个删除公海客户
     * @param idList
     * @return
     */
    @PostMapping("/deleteAccountForHighSea")
    public JSONAware deleteAccountForHighSea(@RequestParam String idList, HttpServletRequest request) {
        if (StringUtils.isEmpty(idList)){
            return RespBody.errorl("PlsSet1FieldShowLeast");
        }
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        log.info("后台-单个删除公海客户:{}", idList);
        ReturnT returnT = xnAccountService.deleteAccountForHighSea(idList);
        if (returnT.getCode() != 200){
            return RespBody.errorl(returnT.getMsg());
        }
        return RespBody.ok();
    }

    /**
     * 前台-单条分派客户
     * @param po
     * @return
     */
    @PostMapping("/assignAccountForHighSea")
    public JSONAware assignAccountForHighSea(@RequestBody AssignAccountPO po, HttpServletRequest request) {
        if (StringUtils.isEmpty(po.getId()) || StringUtils.isEmpty(po.getTo())){
            return RespBody.errorl("PlsSet1FieldShowLeast");
        }
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        log.info("前台-单条分派客户:{}", JSON.toJSON(po));
        ReturnT returnT = xnAccountService.assignAccountForHighSea(po);
        if (returnT.getCode() != 200){
            return RespBody.errorl(returnT.getMsg());
        }
        return RespBody.ok();
    }

    /**
     * 前台-单条领取客户
     * @param id
     * @return
     */
    @RequestMapping("/receiveAccountForHighSea")
    public JSONAware receiveAccountForHighSea(String id, HttpServletRequest request) {
        if (StringUtils.isEmpty(id)){
            return RespBody.errorl("PlsSet1FieldShowLeast");
        }
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        log.info("前台-单条分派客户:{}", id);
        ReturnT returnT = xnAccountService.receiveAccountForHighSea(id);
        if (returnT.getCode() != 200){
            return RespBody.errorl(returnT.getMsg());
        }
        return RespBody.ok();
    }

    /**
     * 前台-新增公海客户
     * @param po
     * @return
     */
    @PostMapping("/addAccountForHighSea")
    public JSONAware addAccountForHighSea(@RequestBody AddXnAccountPO po, HttpServletRequest request){
        if (Objects.isNull(po)){
            return RespBody.errorl("PlsSet1FieldShowLeast");
        }
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        log.info("前台-新增公海客户:{}", JSON.toJSON(po));
        ID currentUser = (ID) ServletUtils.getSessionAttribute(request, WebUtils.CURRENT_USER);
        po.setCreatedBy(currentUser.toString());
        ReturnT returnT = xnAccountService.addAccountForHighSea(po);
        return JSONUtils.toJSONObject(
                new String[] { "id"},
                new Object[] { returnT.getData()});
    }

    /*************************************************************** 前台公海结束 ***************************************************************/
    /*************************************************************** 前台私海开始 ***************************************************************/

    /**
     * 前台-查询私海客户列表
     * @return
     */
    @RequestMapping("/privateSea")
    public ModelAndView selectAccountForPrivateSea(HttpServletRequest request) {
        final ID user = getRequestUser(request);
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        // TODO 未确定前端HTML
        ModelAndView mv = createModelAndView("/xianniu/admin/account/privateSea");
        mv.getModel().put("entityName", "xnaccount");
        mv.getModel().put("entityLabel", "私海客户");
        mv.getModel().put("entityIcon", "entityIcon");
        JSON config = DataListManager.instance.getFieldsLayout("xnaccount", user, tenantCode);
        mv.getModel().put("DataListConfig", JSON.toJSONString(config));
        return mv;
    }

    /**
     * 前台-新增私海客户
     * @param po
     * @return
     */
    @PostMapping("/addAccountForPrivateSea")
    public JSONAware addAccountForPrivateSea(@RequestBody AddXnAccountPO po, HttpServletRequest request){
        if (Objects.isNull(po)){
            return RespBody.errorl("PlsSet1FieldShowLeast");
        }
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        log.info("前台-新增私海客户:{}", JSON.toJSON(po));
        ID currentUser = (ID) ServletUtils.getSessionAttribute(request, WebUtils.CURRENT_USER);
        po.setCreatedBy(currentUser.toString());
        ReturnT returnT = xnAccountService.addAccountForPrivateSea(po);
        return JSONUtils.toJSONObject(
                new String[] { "id"},
                new Object[] { returnT.getData()});
    }

    /**
     * 前台-放回客户池
     * @param po
     * @return
     */
    @PostMapping("/putBackAccountForPrivateSea")
    public JSONAware putBackAccountForPrivateSea(@RequestBody PutAccountPO po, HttpServletRequest request) {
        if (ObjectUtil.isEmpty(po)){
            return RespBody.errorl("PlsSet1FieldShowLeast");
        }
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        log.info("前台-放回客户池:{}", JSON.toJSON(po));
        ReturnT returnT = xnAccountService.putBackAccountForPrivateSea(po);
        if (returnT.getCode() != 200){
            return RespBody.errorl(returnT.getMsg());
        }
        return RespBody.ok();
    }

    /**
     * 强制回收客户到客户池
     * @param po
     * @return
     */
    @PostMapping("/recycleAccountForPrivateSea")
    public JSONAware recycleAccountForPrivateSea(@RequestBody PutAccountPO po, HttpServletRequest request) {
        if (ObjectUtil.isEmpty(po)){
            return RespBody.errorl("PlsSet1FieldShowLeast");
        }
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        log.info("强制回收客户到客户池:{}", JSON.toJSON(po));
        ReturnT returnT = xnAccountService.recycleAccountForPrivateSea(po);
        if (returnT.getCode() != 200){
            return RespBody.errorl(returnT.getMsg());
        }
        return RespBody.ok(returnT.getMsg());
    }

    /**
     * 前台私海-锁定/解锁客户
     * @param id
     * @param request
     * @return
     */
    @GetMapping("/lockAccountForPrivateSea")
    public JSONAware lockAccountForPrivateSea(String id, HttpServletRequest request) {
        if (StringUtils.isEmpty(id)){
            return RespBody.errorl("PlsSet1FieldShowLeast");
        }
        String tenantCode = (String) ServletUtils.getSessionAttribute(request, LoginController.TENANT_CODE);
        UserContextHolder.setTenant(tenantCode);
        log.info("前台私海-锁定/解锁客户:{}", id);

        ReturnT returnT = xnAccountService.lockAccountForPrivateSea(id);
        if (returnT.getCode() != 200){
            return RespBody.errorl(returnT.getMsg());
        }
        return new RespBody(Controller.CODE_OK, returnT.getMsg(), null);
    }
    /*************************************************************** 前台私海结束 ***************************************************************/

    public JSON buildAccountAdminDataListConfig(){
        List<Map<String, Object>> columnList = new ArrayList<>();
        Map<String, Object> m1 = JSONUtils.toJSONObject(
                new String[]{"field", "type", "label"},
                new Object[]{"kehumingcheng", "TEXT", "客户名称"});
        Map<String, Object> m2 = JSONUtils.toJSONObject(
                new String[]{"field", "type", "label"},
                new Object[]{"teamName", "TEXT", "所属线索池"});
        Map<String, Object> m3 = JSONUtils.toJSONObject(
                new String[]{"field", "type", "label"},
                new Object[]{"createdBy", "TEXT", "创建人"});
        Map<String, Object> m4 = JSONUtils.toJSONObject(
                new String[]{"field", "type", "label"},
                new Object[]{"createdOn", "TEXT", "创建时间"});
        Map<String, Object> m5 = JSONUtils.toJSONObject(
                new String[]{"field", "type", "label"},
                new Object[]{"receiveBy", "TEXT", "领取人"});
        Map<String, Object> m6 = JSONUtils.toJSONObject(
                new String[]{"field", "type", "label"},
                new Object[]{"receiveOn", "TEXT", "领取时间"});
        Map<String, Object> m7 = JSONUtils.toJSONObject(
                new String[]{"field", "type", "label"},
                new Object[]{"receiveStatus", "TEXT", "领取状态"});
        Map<String, Object> m8 = JSONUtils.toJSONObject(
                new String[]{"field", "type", "label"},
                new Object[]{"kehuzhuangtai", "TEXT", "客户状态"});
        columnList.add(m1);
        columnList.add(m2);
        columnList.add(m3);
        columnList.add(m4);
        columnList.add(m5);
        columnList.add(m6);
        columnList.add(m7);
        columnList.add(m8);
        return JSONUtils.toJSONObject(
                new String[]{"entity", "nameField", "fields"},
                new Object[]{"xnaccount", "accountId", columnList});
    }


}
